#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
#include <algorithm>
using namespace std;


int main()
{
    int times;
    cin >> times;
    int sum; string s;
    while (times--)
    {
        int a = 0, b = 0, c = 0, d = 0;
        cin >> sum;
        cin >> s;

        for (int left = 0, right; right = left + 5, right <= sum; left += 5)
        {
            if (count(s.begin() + left, s.begin() + right, 'R') >= 3)
                b++;
            else if (count(s.begin() + left, s.begin() + right, 'G') >= 3)
                c++;
            else if (count(s.begin() + left, s.begin() + right, 'B') >= 3)
                d++;
            else
                a++;
        }
        cout << a << ' ' << b << ' ' << c << ' ' << d << endl;

    }

    return 0;
}


long long sum(int a, int b)
{
    return a + (a + b) * (a + b);
}
int main()
{
    long long times;
    cin >> times;
    while (times--)
    {
        long long n, m, s, ret = 0;
        cin >> n >> m >> s;
        while (s)
        {
            if (sum(n, m) <= s)
            {
                cout << s << endl;
                break;
            }
            for (int i = n; i >= 0; i--)
            {
                for (int j = m; j >= 0; j--)
                {
                    ret = sum(i, j);
                    if (ret > s)
                        continue;
                    else if (ret == s)
                    {
                        break;
                    }
                    else
                        break;
                }
                if (s == ret)
                {
                    cout << ret << endl;
                    break;
                }

            }
            if (s == ret)
            {
                break;
            }
            s--;
        }

    }

}